package com.why.blog.common.utils;

import eu.bitwalker.useragentutils.UserAgent;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

 /**
  * @Title: 用户访问 请求信息解析
  * @Description: 用户访问 请求信息解析
  * @Param:
  * @Return:
  * @Author: TriggerWu
  * @Date: 2019/5/8
  * @Time: 10:10
 **/
public class AccessTerminalUtil {

	/**
	 * 用户请求 'User-Agent' 请求头解析
	 * @param request HttpServletRequest
	 * @return
	 */
	public static Map<String, String> userAgentParse(HttpServletRequest request) {
		String ua = request.getHeader("User-Agent");
		UserAgent userAgent = UserAgent.parseUserAgentString(ua);

		Map<String, String> map = new HashMap<String, String>() {{
			put("browser", userAgent.getBrowser().getName());
			put("browserVersion", userAgent.getBrowser().getVersion(ua).toString());
			put("os", userAgent.getOperatingSystem().getName());
		}};

		return map;
	}

}
